/*
 * @lc app=leetcode.cn id=154 lang=cpp
 * @lcpr version=30204
 *
 * [154] 寻找旋转排序数组中的最小值 II
 */

// @lcpr-template-start
using namespace std;
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
// @lcpr-template-end
// @lc code=start
class Solution
{
public:
    int findMin(vector<int> &nums)
    {
        int n = nums.size();
        if (n == 0)
        {
            return -1;
        }
        if(n == 1)
        {
            return nums[0];
        }

        int left = 0;
        int right = n - 1;
        int mid = left;
        while (left < right)
        {
            mid = (left + right) >> 1;

            if(nums[left] == nums[mid] && nums[mid] == nums[right])
            {
                left++;
                right--;
            }
            else if(nums[mid] <= nums[right])
            {
                right = mid;
            }
            else
            {
                left = mid +1;
            }
           
        }
        return nums[left];
    }
};
// @lc code=end

/*
// @lcpr case=start
// [1,3,5]\n
// @lcpr case=end

// @lcpr case=start
// [2,2,2,0,1]\n
// @lcpr case=end

 */
